package com.geek.java.ch04.List;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Test {
    public static void main(String[] args) {

        Scanner sc=new Scanner(System.in);

        ArrayList<User> account = new ArrayList<>();

        account.add(new User("111", "123456"));
        account.add(new User("222", "qwerty"));
        account.add(new User("333", "333333"));
        account.add(new User("444", "444444"));
        account.add(new User("555", "555555"));



        List<User> aList= account.stream().collect(Collectors.toList());
        System.out.println(aList);

        int count=3;
        boolean flag=false;
        while(!flag) {
            System.out.println("请输入用户名：");
            String userName=sc.nextLine();
            System.out.println("请输入密码：");
            String passWord=sc.nextLine();
            count--;
            for (int i = 0; i < account.size(); i++) {
                if (account.get(i).getUserName().equals(userName) && account.get(i).getPassWord().equals(passWord)) {
                    flag = true;
                    System.out.println("登入成功");
                }
            }

            if(count==0) {
                System.out.println("你的机会已经用完了，欢迎下次使用。");
                return;
            }
            if(count!=0&&flag==false) {
                System.out.println("用户名或密码错误，你还有" + count + "次机会，" + "请重新输入。");
                System.out.println("====================================================");
            }

        }

    }


}
